import React from 'react'
import { Spin } from 'antd'
import {messages} from "share/common";

import CardTitle from "containers/dashboard/dashboard-component/card-title"
import moment from "moment/moment";
import updateLogService from "containers/help-center-user/update-log/update-log.service";
import menuRoute from "routes/menuRoute";

class UpdateLog extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      load: false,
      logs: []
    }
  }

  componentWillMount() {
    this.getUpdateLogList()
  }

  getUpdateLogList = () => {
    updateLogService.getUpdateLogList().then(res => {
      this.setState({
        logs: res.data,
      })
    })
  };

  goUpdateLog = () => {
    window.open(`${window.ISIE9 ? "#" : ""}${menuRoute.getRouteItem('update-log','key').url}`, '_blank');
  };

  render() {
    const {load, logs} = this.state;
    const {removeModule} = this.props;
    return (
      <Spin spinning={load}>
        <CardTitle  cardKey={"4"}
                    title={messages('dashboard.key152')/*更新日志*/}
                    removeModule={(key) => removeModule(key)}
                    reloadModule={() => {}}/>
        <div className="card-content">
          <div className="version">
            {
              logs.length ?
                <div>
                  <p className="version-date">{moment(logs[0].publishDate).format('YYYY-MM-DD')}, {messages('dashboard.key161')/*我们又努力更新了以下功能*/}：</p>
                  <p className="version-number">{`V ${logs[0].version}`}</p>
                  <div className="log" dangerouslySetInnerHTML={{__html: logs[0].content}}/>
                  <p className="view-all" onClick={this.goUpdateLog}>{messages('help-center-user.key19')/*查看全部*/}</p>
                </div>
                :
                <h4>{messages('help-center-user.key22')/*当前暂无更新日志*/}</h4>
            }
          </div>
        </div>
      </Spin>
    )
  }
}

UpdateLog.contextTypes = {
  router: React.PropTypes.object
};

UpdateLog.propTypes = {
  removeModule: React.PropTypes.func.isRequired,
};

UpdateLog.defaultProps={
};

export default UpdateLog;
